package ext.tianma.part.processors;

import java.io.File;
import java.io.Serializable;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import wt.inf.container.WTContainer;
import wt.inf.container.WTContainerRef;
import wt.method.RemoteAccess;
import wt.util.WTException;
import wt.util.WTProperties;

import com.ptc.core.components.beans.ObjectBean;
import com.ptc.core.components.forms.DefaultObjectFormProcessor;
import com.ptc.core.components.forms.FormProcessingStatus;
import com.ptc.core.components.forms.FormResult;
import com.ptc.core.components.util.FeedbackMessage;
import com.ptc.core.ui.resources.FeedbackType;
import com.ptc.netmarkets.model.NmOid;
import com.ptc.netmarkets.util.beans.NmCommandBean;

import ext.tianma.number.util.UpdatePart;


public class UpdatePartProcessor extends DefaultObjectFormProcessor implements RemoteAccess, Serializable{
	private static boolean VERBOSE = false;
    private static String CLASSNAME = UpdatePartProcessor.class.getName();
    private static final String RESOURCE = "ext.tianma.part.resource.partClientResource";
    static
    {
        try
        {
            WTProperties wtproperties = WTProperties.getLocalProperties();
            VERBOSE = wtproperties.getProperty("ext.tianma.part.verbose", false);
        }
        catch (Throwable throwable)
        {
            throwable.printStackTrace(System.err);
            throw new ExceptionInInitializerError(throwable);
        }
    }
	
	
	 public FormResult doOperation(NmCommandBean arg0, List<ObjectBean> arg1) throws WTException {		 
		 System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<进入方法");
		 FormResult formresult = new FormResult();
		 formresult.setStatus(FormProcessingStatus.SUCCESS);
		 NmOid nmoid = arg0.getActionOid();
		 WTContainer currentPart = (WTContainer) nmoid.getRefObject();
		 WTContainerRef ref = WTContainerRef.newWTContainerRef(currentPart);
		 HttpServletRequest request = arg0.getRequest();
		 File file1 = (File) request.getAttribute("fileNumber");
		 System.out.println("file>>>>>>="+file1);
		 String fileNumber = file1.getAbsolutePath(); 
		 System.out.println("fileNumber》》》》》》》》="+fileNumber);
		 String checkFile="";
		 checkFile = fileNumber.substring(fileNumber.lastIndexOf(".")+1);
		 System.out.println("checkFile》》》》》》》》="+checkFile);
		 UpdatePart.doImportFillPart(fileNumber, ref);
		 FeedbackMessage feedbackmessage = new FeedbackMessage(
					FeedbackType.SUCCESS, null, "物料导入成功!", null, new String[] {});
			formresult.addFeedbackMessage(feedbackmessage);
		 return formresult;
	 }
}
